﻿@{
    ViewBag.Title = "ReportList";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var curSelectNode = null;
        var Userid = "";
        var _rowId = "";
        var CurrOrganizationID = '@ViewBag.CurrOrganizationID';//当前登录用户所在的部门，主要用于在grid中，将当前单位的记录显示醒目色。
        $(document).ready(function () {
            switch ('@ViewBag.Cycle') {
                case "01": //月报
                    $("#ListYear").val('@ViewBag.CurYear');
                    $("#ListMonth").val('@ViewBag.CurMonth');
                    break;
                case "02": //季报
                    $("#ListYear").val('@ViewBag.CurYear');
                    $("#ListMonth").val('@ViewBag.CurSeason');
                    break;
                case "03": //年报
                    $("#ListYear").val('@ViewBag.CurYear');
                    break;
                default:
            }
            funGridInit();
            $("#OrganizationName").keydown(function (even) {
                var curKey = even.which;
                if (curKey == 13) {
                    if ($("#OrganizationName").val().length > 0)
                    { Search(); }
                }
            });
        });

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }

        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 101,
                width: $("#divGridContainer").width() - 2,
                url: '/DataManage/Report/ReportGetList?reportid=@ViewBag.REPORTID',
                autowidth: false,
                datatype: "json",
                sortname: 'SubmitInfo_OrganizationID',
                sortorder: 'asc',
                colModel: [
                { label: '报表名称', name: 'Report_Name', width: 200, sortable: false },
                { label: '单位名称', name: 'Organization_Name', width: 150, sortable: false },
                { label: '报表类型', name: 'SubmitInfo_Cycle', width: 70, align: "center", sortable: false, formatter: 'select', editoptions: { value: "01:月报;02:季报;03:年报"} },
                { label: '报表期间', name: 'QJ', width: 100, align: "center", sortable: false },
                { label: '创建日期', name: 'SubmitInfo_CreateDate', width: 100, align: "center", sortable: false },
                { label: '截止上报日期', name: 'SubmitInfo_EndDate', width: 100, align: "center", sortable: false },
                { label: '延迟上报日期', name: 'SubmitInfo_LazyDate', width: 100, align: "center", sortable: false },
                { label: '制表人', name: 'SubmitInfo_CreatorName', width: 70, align: "center", sortable: false },
                { label: '上报状态', name: 'SubmitInfo_State', width: 70, align: "center", sortable: false, formatter: 'select', editoptions: { value: "0:未上报;1:已上报;2:已汇总"} },
                { label: '报出日期', name: 'SubmitInfo_SubmitDate', width: 100, align: "center", sortable: false },
                { label: '数据来源', name: 'SubmitInfo_Sjly', width: 100, align: "center", sortable: false },
                { name: 'SubmitInfo_ID', hidden: true },
                { name: 'SubmitInfo_Year', hidden: true },
                { name: 'SubmitInfo_Month', hidden: true },
                { name: 'SubmitInfo_Day', hidden: true },
                { name: 'SubmitInfo_ReportID', hidden: true },
                { name: 'SubmitInfo_OrganizationID', hidden: true }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    _rowId = rowid;
                },
                ondblClickRow: function (rowid) {
                    _rowId = rowid;
                    EditReport();
                },
                beforeRequest: function (d) {
                    //var data = { organizeId: curSelectNode == null ? '' : curSelectNode.organization_id };
                    var data = { 'queryData': $('#queryForm').serialize() };
                    $(gridId).jqGrid('setGridParam', { postData: data });
                },
                gridComplete: function () {
                    var _rownum = $(gridId).getDataIDs().length;
                    for (var i = 1; i <= _rownum; i++) {
                        var cycle = $(gridId).getCell(i, "SubmitInfo_Cycle");
                        var str_year = $(gridId).getCell(i, "SubmitInfo_Year");
                        var str_month = $(gridId).getCell(i, "SubmitInfo_Month");
                        var str_day = $(gridId).getCell(i, "SubmitInfo_Day");
                        var str_EndDate = $(gridId).getCell(i, "SubmitInfo_EndDate");
                        var str_LazyDate = $(gridId).getCell(i, "SubmitInfo_LazyDate");
                        $(gridId).setCell(i, "QJ", DateTimeStr(cycle, str_year, str_month, str_day));

                        //将当前部门所在行变色，醒目显示
                        var bkcolor;
                        var org_id = $(gridId).getCell(i, "SubmitInfo_OrganizationID");
                        bkcolor = "#32cd32"; //橘红色F7983A  
                        if (org_id == CurrOrganizationID) {
                            var celldata = $(gridId).getCell(i, "Organization_Name");
                            $(gridId).setCell(i, "Organization_Name", celldata, { background: bkcolor });
                            //                            var rowdata = $(gridId).getRowData(i);
                            //                            $(gridId).setRowData(i, rowdata, { background: bkcolor });

                        }
                        //设置已上报状态为#CC6600
                        var State = $(gridId).getCell(i, "SubmitInfo_State");
                        bkcolor = "#CCFF00"; //橘红色F7983A  
                        if (State == "1") {
                            var celldata = $(gridId).getCell(i, "SubmitInfo_State");
                            $(gridId).setCell(i, "SubmitInfo_State", celldata, { background: bkcolor });
                            //                            var rowdata = $(gridId).getRowData(i);
                            //                            $(gridId).setRowData(i, rowdata, { background: bkcolor });

                        }


                        //将已经延迟上报的变色为#FFCC00
                        if (str_EndDate != str_LazyDate) {
                            bkcolor = "#FFCC00"; //橘红色F7983A  
                            $(gridId).setCell(i, "SubmitInfo_LazyDate", str_LazyDate, { background: bkcolor });
                        }
                    }
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }

        function loadGrid() {
            $(gridId).trigger("reloadGrid");
        }

        function EditReport() {
            var selectedId = $(gridId).jqGrid("getGridParam", "selrow");
            if (selectedId == null) {
                top.asyncbox.alert('请选择报表!', '提示');
                return;
            }
            var rowData = $(gridId).jqGrid("getRowData", selectedId);
            var url = '/DataManage/Report/Index/' + rowData.SubmitInfo_ID;

            if ('@ViewBag.NSRWQWReportID' == '@ViewBag.REPORTID') {
                url = '/DataManage/Report/NSRWQWQYYL/' + rowData.SubmitInfo_ID;
            }
            //河南省规模以上休闲农业企业主要经济指标季报表
            if ('@ViewBag.XXNYQYJBReportID' == '@ViewBag.REPORTID') {
                url = '/DataManage/Report/XXNYQYJB/' + rowData.SubmitInfo_ID;
            }
            if ('@ViewBag.NYCYHLTQYNBReportID' == '@ViewBag.REPORTID') {
                url = '/DataManage/Report/NYCYHLTQYNB/' + rowData.SubmitInfo_ID;
            }
            //农业产业化龙头企业季报
            if ('@ViewBag.NYCYHLTQYJBReportID' == '@ViewBag.REPORTID') {
                url = '/DataManage/Report/NYCYHLTQYJB/' + rowData.SubmitInfo_ID;
            }
            top.asyncbox.open({
                title: rowData.Report_Name,
                url: url,
                width: window.screen.availWidth - 100, // $(document).width(),
                height: window.screen.availHeight - 200, // $(document).height(),
                modal: true //模态（遮罩层），一定程度上屏蔽用户对本窗口以外的操作。 
                //drag:true//拖动窗口。
            });
        }
        function sumitinfodel() {
            //删除方法 Add 2013-06-22
            $.funListDelete(gridId, "SubmitInfo_ID", '@Url.Content("~/SystemManage/SubmitInfo/DeleteSubmitInfo")');
        }

        function sumData() {
            //数据汇总
            //if (_rowId == null || _rowId == "") return;
            //var repid = $(gridId).getCell(_rowId, "SubmitInfo_ReportID");
            //            var syear = $(gridId).getCell(_rowId, "SubmitInfo_Year");
            //            var smonth = $(gridId).getCell(_rowId, "SubmitInfo_Month");
            //            var scycle = $(gridId).getCell(_rowId, "SubmitInfo_Cycle");
            //报表下发模式发生变化，在进行汇总时，该单个可能还没有产生该报表下的数据 
            //Modified 2013-06-21  
            //根据报表ID 与所选择年度 与 月份进行处理
            //            var repid = '@ViewBag.REPORTID'; //
            //            var syear = $("#ListYear").val();
            //            var smonth = $("#ListMonth").val();
            //            if (repid == null || repid == "") {
            //                alert("报表ID不能为空!");
            //                return;
            //            }
            //            if (syear == null || syear == "") {
            //                alert("请选择查询年份!");
            //                return;
            //            }
            //            if ('@ViewBag.Cycle' == "01" || '@ViewBag.Cycle' == "02") {
            //                if (smonth == null || smonth == "") {
            //                    alert("请选择查询月份/季度!");
            //                    return;
            //                }
            //            }
            if (!confirm('警告：汇总会清除之前存在的数据重新汇总下级上报的数据，确定继续吗？')) return;
            var reportid = '@ViewBag.REPORTID'
            var u = "/SystemManage/SubmitInfo/ChoosecollectDate?ReprotId=" + reportid;
            parent.asyncbox.open({
                url: u,
                data: '',
                title: "选择期间及单位",
                width: 400,
                height: 320,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action, opener) {
                    if (action == 'ok') {
                        var nian = opener.document.getElementById("Year").value;
                        var yue = opener.document.getElementById("Month").value;
                        var jd = opener.document.getElementById("JD").value;
                        var org = DialogFrame($(this).attr("id")).GetSelectedorg();
                        var smonth = '';
                      
                        /*将汇总时间反写给查询条件时间 ，这样当汇总后，可以直接看到记录，否则当前为10月份，汇总9月的，汇总后显示的是10月的记录，让人以为没有汇总成功*/
                        $("#ListYear").val(nian);
                        if ('@ViewBag.Cycle' == '01') {
                            smonth = yue;
                            $("#ListMonth").val(smonth);
                        }
                        if ('@ViewBag.Cycle' == '02') {
                            smonth = jd;
                            $("#ListMonth").val(smonth);
                        }

                        

                        parent.showloading();
                        $.post("/DataManage/Report/SumReportData", { reportid: reportid, year: nian, month: smonth, jd: jd, org: org }, function (d) {
                            parent.hideloading();
                            if (d == null || d == "") {
                                parent.asyncbox.alert('汇总成功!', '提示');
                                $(gridId).trigger("reloadGrid");
                            }
                            else {
                                parent.asyncbox.alert(d, '提示');
                            }
                        });

                    }
                    if (action == 'cancel') {
                        return;
                    }
                }
            });

        }

        //设置延迟上报
        function setLazyDate() {
            var selectedId = $(gridId).jqGrid("getGridParam", "selrow");
            if (selectedId == null) {
                top.asyncbox.alert('请选择报表!', '提示');
                return;
            }
            var rowData = $(gridId).jqGrid("getRowData", selectedId);
            var _submitInfoID = rowData.SubmitInfo_ID;
            parent.asyncbox.open({
                url: "/SystemManage/SubmitInfo/ChooseLazyDate",
                title: "选择期间",
                width: 400,
                height: 320,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action, opener) {
                    if (action == 'ok') {
                        var _date = opener.document.getElementById("lazyDate").value;
                        $.post('/SystemManage/SubmitInfo/SetLazyDate', { submitInfoID: _submitInfoID, lazyDate: _date }, function (msg) {
                            if (msg.ErrorMessage.length > 0) {
                                parent.asyncbox.alert(msg.ErrorMessage, '提示');
                                return false;
                            }
                            else {
                                parent.asyncbox.tips('操作成功!', 'success', 1500);
                                loadGrid();
                            }
                        });
                    }
                    if (action == 'cancel') {
                        return;
                    }
                }
            });
        }

        //新增报表
        function sumitinfoadd() {
            var reportid = '@ViewBag.REPORTID'
            var u = "/SystemManage/SubmitInfo/ChooseDate?ReprotId=" + reportid;
            parent.asyncbox.open({
                url: u,
                data: '',
                title: "选择期间",
                width: 400,
                height: 320,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action, opener) {
                    if (action == 'ok') {
                        var nian = opener.document.getElementById("Year").value;
                        var yue = opener.document.getElementById("Month").value;
                        var jd = opener.document.getElementById("JD").value;

                        var smonth = '';
                        /*将汇总时间反写给查询条件时间 ，这样当汇总后，可以直接看到记录，否则当前为10月份，汇总9月的，汇总后显示的是10月的记录，让人以为没有汇总成功*/
                        $("#ListYear").val(nian);
                        if ('@ViewBag.Cycle' == '01') {
                            smonth = yue;
                            $("#ListMonth").val(smonth);
                        }
                        if ('@ViewBag.Cycle' == '02') {
                            smonth = jd;
                            $("#ListMonth").val(smonth);
                        }
                       

                        parent.showloading();
                        $.post("/SystemManage/SubmitInfo/SetReportPublish/", { ReportId: reportid, sYear: nian, sMonth: yue, sJd: jd }, function (d) {
                            if (d == "" || d == null) {
                                parent.hideloading();
                                parent.asyncbox.tips('新增报表成功!', 'success', 1500);
                                Search();
                            }
                            else {
                                parent.hideloading();
                                parent.asyncbox.alert(d, '提示');
                            }
                        });
                    }
                    if (action == 'cancel') {
                        return;
                    }
                }
            });
        }

        function sumitinfostate(state) {
            var selectedId = $(gridId).jqGrid("getGridParam", "selrow");
            if (selectedId == null) {
                top.asyncbox.alert('请选择报表!', '提示');
                return;
            }
            var info = "";
            if (state == "0")
                info = "取消上报"
            else
                info = "上报"
            var rowData = $(gridId).jqGrid("getRowData", selectedId);
            if (rowData.SubmitInfo_State == state) {
                top.asyncbox.tips("不能进行操作,请确认状态", 'error');
                return false;
            }
            top.asyncbox.confirm("确定" + info + "该报表?", "提示", function (action) {
                if (action == 'ok') {
                    $.ajax({
                        type: "POST",
                        url: "/DataManage/Report/ChangeSubmitState",
                        data: "submitinfoid=" + rowData.SubmitInfo_ID + "&state=" + state,
                        success: function (msg) {
                            if (msg.length == 0) {
                                loadGrid();
                                top.asyncbox.tips(info + '成功!', 'success');
                            }
                            else
                                top.asyncbox.tips(msg, 'error');
                        }
                    });
                }
            });
        }
    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle" style="z-index:-1;">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right:20px;">
        <a onclick="sumitinfoadd()" class="button green"><span class="icon-botton" style="background: url('/Content/16/add.png') no-repeat scroll 0px 4px;"></span>
        新增</a>
        <a onclick="sumitinfodel()" class="button green"><span class="icon-botton" style="background: url('/Content/16/delete.png') no-repeat scroll 0px 4px;"></span>
        删除</a> 
        <a onclick="EditReport()" class="button green"><span class="icon-botton" style="background: url('/Content/16/edit.png') no-repeat scroll 0px 4px;"></span>
        编辑</a>
        <a onclick="sumData()" class="button green"><span class="icon-botton" style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>
        数据汇总</a>
        <a onclick="sumitinfostate(1)" class="button green"><span class="icon-botton" style="background: url('/Content/16/easyicon_net_16.png') no-repeat scroll 0px 4px;"></span>
        上报</a> 
        <a onclick="sumitinfostate(0)" class="button green"><span class="icon-botton" style="background: url('/Content/16/cancel.png') no-repeat scroll 0px 4px;"></span>
        取消上报</a> 
        <a onclick="setLazyDate()" class="button green"><span class="icon-botton" style="background: url('/Content/16/clock_start.png') no-repeat scroll 0px 4px;"></span>
        延迟上报</a>
    </div>
</div>
<!--主窗体，页面都需要的div-->
@*<div id="divPageSearsh" class="ui-widget-background my-pageSearsh">
    <form action="#" id="queryForm" method="post">
    <div class="l-left">
        <div class='l-col' style="padding-left: 5px;">
            @Html.Label("CXYear", "查询年度:")
            @Html.DropDownList("ListYear", new SelectList(ViewBag.ListYear, "Key", "Value"), new { style = "width:100px;" })
            @Html.Label("CXMonth", "查询月份:")
            @Html.DropDownList("ListMonth", new SelectList(ViewBag.ListMonth, "Key", "Value"), new { style = "width:100px;" })
            <a onclick="Search()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;">
            </span>查询</a>
        </div>
    </div>
    </form>
</div>*@
<div id="divGridContainer" class="ui-layout-center" style="overflow: hidden;">
    @if ((ViewBag.Cycle) == "01")
    {
        @Html.Partial("_Cycle01")
    }
    else if ((ViewBag.Cycle) == "02")
    {
        @Html.Partial("_Cycle02")
    }
    else
    {
        @Html.Partial("_Cycle03")
    }

    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
